// pages/order/order.ts
import { request, api } from "../../utils/request"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    pageSize: 4,
    orderList: [],
    total: 0,
    isLoading: true,
    goodsTotalPrice: "",
    orderId: 0
  },
  payPopupClose() {
    this.setData({
      show: false,
      page: 1,
      orderList: [],
      totalPage: 0
    })
    this.getOrderList()
  },
  async submitOrder(params) {
    let item = params.detail
    console.log(params);

    this.setData({
      show: true,
      orderId: item.orderId,
      goodsTotalPrice: item.actualPrice
    })
  },

  async getOrderList() {
    this.setData({
      isLoading: true
    })
    let res = await request(api.OrderList, {
      showType: 0,
      page: this.data.page,
      size: this.data.pageSize
    })
    console.log(res);
    
    if (res.errno === 0) {
      console.log(res.data);
      this.setData({
        orderList: this.data.orderList.concat(res.data.data),
        total: res.data.totalPages
      });
    }
    this.setData({
      isLoading: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.getOrderList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total) {
      return wx.showToast({title: '到底了！',icon: 'none'})
    }
    if (this.data.isLoading) {
      return
    }
    this.setData({
      page: this.data.page + 1
    })
    this.getOrderList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})